package com.sailfish.springbootdemo.controller.db1;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.PcbaDevice;
import com.sailfish.springbootdemo.service.db1.PcbaDeviceService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@CrossOrigin
@RequestMapping("/pcbaDevice")
public class PcbaDeviceController {

    @Autowired
    private PcbaDeviceService pcbaDeviceService;

    @PostMapping("/getAllPcbaDevice")
    public Result getAllPcbaDevice(Integer pcbaDeviceTypeId, String searchValue, Integer status, Integer pageSize, Integer page, Integer pcbaCompanyId, Integer pcbaWorkshopId, Integer pcbaProcessId, Integer isFilledUpkeep) {
        return pcbaDeviceService.getAllPcbaDevice(pcbaDeviceTypeId, searchValue, status, pageSize, page, pcbaCompanyId, pcbaWorkshopId, pcbaProcessId, isFilledUpkeep);
    }

    @PostMapping("/deleteById")
    public Result deleteById(Integer pcbaDeviceId) {
        return pcbaDeviceService.deleteById(pcbaDeviceId);
    }

    @PostMapping("/updatePcbaDevice")
    public Result updatePcbaDevice(PcbaDevice pcbaDevice) {
        return pcbaDeviceService.updatePcbaDevice(pcbaDevice);
    }

    @PostMapping("/getPcbaDeviceById")
    public Result getPcbaDeviceById(Integer pcbaDeviceId) {
        try {
            if (pcbaDeviceId == null || "".equals(pcbaDeviceId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaDeviceId", "Miss Param pcbaDeviceId", null);
            }
            return ResultUtil.success(pcbaDeviceService.getPcbaDeviceById(pcbaDeviceId));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/adjustDeviceSort")
    public Result adjustDeviceSort(String type, Integer pcbaLineId, Integer pcbaDeviceId) {
        return pcbaDeviceService.adjustDeviceSort(type, pcbaLineId, pcbaDeviceId);
    }

    @PostMapping("/addOrUpdateTechAndParamRelatedActual")
    public Result addOrUpdateTechAndParamRelatedActual(@RequestBody String data) {
        return pcbaDeviceService.addOrUpdateTechAndParamRelatedActual(data);
    }

    @PostMapping("/getTechParamValueAndTechParamValueActual")
    public Result getTechParamValueAndTechParamValueActual(Integer pcbaDeviceId, Integer pcbaDeviceResourceId, Integer pcbaDeviceTypeId) {
        return pcbaDeviceService.getTechParamValueAndTechParamValueActual(pcbaDeviceId, pcbaDeviceResourceId, pcbaDeviceTypeId);
    }

    @PostMapping("/getPcbaParamValue")
    public Result getPcbaParamValue(Integer pcbaDeviceTypeId, Integer pcbaDeviceResourceId) {
        return pcbaDeviceService.getPcbaParamValue(pcbaDeviceTypeId, pcbaDeviceResourceId);
    }

    @PostMapping("/exportDeviceListExcel")
    public Result exportDeviceListExcel(String searchValue, Integer status, Integer pcbaCompanyId, Integer pcbaWorkshopId, Integer pcbaProcessId, Integer isFilledUpkeep) {
        return pcbaDeviceService.exportDeviceListExcel(searchValue, status, pcbaCompanyId, pcbaWorkshopId, pcbaProcessId, isFilledUpkeep);
    }

    @PostMapping("/importDeviceUpkeepListExcel")
    public Result importDeviceUpkeepListExcel(MultipartFile file) {
        return pcbaDeviceService.importDeviceUpkeepListExcel(file);
    }

    @PostMapping("/auditPcbaDevice")
    public Result auditPcbaDevice(String paramsNotes, Integer pcbaDeviceId, Integer paramsStatus) {
        return pcbaDeviceService.auditPcbaDevice(paramsNotes, pcbaDeviceId, paramsStatus);
    }

    @PostMapping("/autoAuditDeviceAndLineWithoutTechParam")
    public Result autoAuditDeviceAndLineWithoutTechParam(Integer pcbaDeviceId) {
        return pcbaDeviceService.autoAuditDeviceAndLineWithoutTechParam(pcbaDeviceId);
    }

    @PostMapping("/handleHighLoopClose")
    public Result handleHighLoopClose(Integer pcbaDeviceId, Integer loopCloseStatus,String loopCloseAuditReason) {
        return pcbaDeviceService.handleHighLoopClose(pcbaDeviceId, loopCloseStatus, loopCloseAuditReason);
    }

    @PostMapping("/handleAgeLoopClose")
    public Result handleAgeLoopClose(Integer pcbaDeviceId, Integer ageCloseStatus, String ageCloseAuditReason) {
        return pcbaDeviceService.handleAgeLoopClose(pcbaDeviceId, ageCloseStatus, ageCloseAuditReason);
    }

    @PostMapping("/goSubmitLoopClose")
    public Result goSubmitLoopClose(Integer pcbaDeviceId, Integer loopCloseMethod, String loopCloseRemark, String loopCloseFiles) {
        return pcbaDeviceService.goSubmitLoopClose(pcbaDeviceId, loopCloseMethod, loopCloseRemark, loopCloseFiles);
    }

    @PostMapping("/goSubmitAgeClose")
    public Result goSubmitAgeClose(Integer pcbaDeviceId, Integer ageCloseMethod, String ageCloseRemark, String ageCloseFiles) {
        return pcbaDeviceService.goSubmitAgeClose(pcbaDeviceId, ageCloseMethod, ageCloseRemark, ageCloseFiles);
    }

    @PostMapping("/queryAllAssetNumberDevices")
    public Result queryAllAssetNumberDevices(String chooseCompanyAndWorkshop, String assetNumber, Integer handledType, Integer pcbaDeviceTypeId, Integer brandId, Integer brandTypeId, Integer page, Integer pageSize) {
        return pcbaDeviceService.queryAllAssetNumberDevices(chooseCompanyAndWorkshop, assetNumber, handledType, pcbaDeviceTypeId, brandId, brandTypeId, page, pageSize);
    }

    @PostMapping("/addDeviceAuditHistory")
    public Result addDeviceAuditHistory(Integer pcbaDeviceId, Integer type, Integer closeMethod, String closeRemark, String closeFiles) {
        return pcbaDeviceService.addDeviceAuditHistory(pcbaDeviceId, type, closeMethod, closeRemark, closeFiles);
    }

    /*@PostMapping("/addOrUpdateDeviceAndParamRelated")
    public Result addOrUpdateDeviceAndParamRelated(@RequestBody String data){
        return pcbaDeviceService.addOrUpdateDeviceAndParamRelated(data);
    }*/
}
